<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page errorPage="WEB-INF/bledy.jsp"%>
<%@page import="java.util.Properties"%>
<%@page import="javax.mail.*" %>
<%@page import="javax.mail.internet.*" %>
<%@page import="java.util.Date"%>

<%
// w celu poprawnie dzialajacej sesji:
response.setHeader("Cache-Control","no-store"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", 0); 
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="UTF-8" src="walidator.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Drukarnia</title>
</head>
<body>

		<%	request.setCharacterEncoding("UTF-8");
			String message = request.getParameter("message");
		
			if(message != null){ %>
				<h3 style="text-align: center; color: rgb(255, 170, 51); background-color: rgb(171, 3, 87); padding: 5px; margin: 0px;">
				
				<% out.println(message);
			}	
		%></h3>
<%
if(( request.getParameter("order") == null || request.getParameter("order") == "")){
%>
<jsp:include page="session1.jsp"></jsp:include>
<%
}else{
%>
<jsp:include page="session1.jsp"></jsp:include>
<%	
String name= request.getParameter("fileName");
String mail= request.getParameter("mail");
String correct1= request.getParameter("correct");
	String addressFrom = "jaclaw90@gmail.com";
String addressTo   = mail;
String mailSubject = "Potwierdzenie złożenia zamówienia nr "+correct1;
String mailBody    = "Witaj " + mail + ", \n \n" +
                     "Dokonałeś zamówienia na naszej stronie. \n \n" +
					"Oto szczegóły zamówienia: \n"+
					"Nr zamówienia: "+ correct1 + "\n" +
					"Załadownany Plik: "+ name + "\n" +
					"Status: Oczekujący na realizację \n" +
					"Będziemy informować państwa na bieżąco o zmianie statusu zamówienia. \n \n" + 
					"Dane do przelewu: \n"+
					"Agencja Reklamowo-Handlowa 'Finezja' M.Ożóg \n" + 
					"ul. Zakopiańska 173 \n" + 
					"30-435 Kraków \n" + 
					"Nr rachunku: 44 85910007 0050 0490 5106 0001 \n \n";


try {
    
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.socketFactory.fallback", false);
    		
    Session mailSession = Session.getInstance(props,
            new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication("mocny.druk@gmail.com","drukarnia1");
//                             return new PasswordAuthentication("biuro@mocnydruk.pl","lafinezja01");
                    }
            });       
                
    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress(addressFrom)); //nadawca
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(addressTo)); //odbiorca  
    msg.setSubject(mailSubject); //temat
    msg.setText(mailBody); 
    msg.setSentDate(new Date());
    
            
    
   Transport.send(msg);
} catch (MessagingException e) {
		throw new RuntimeException(e);
	} 
}
%>






</body>
</html>